import cv2
import numpy as np

# 读取原始图像
image = cv2.imread('C:/Users/1234/Desktop/yolotestdata/23.05.251/circle+circlering/1.bmp', cv2.IMREAD_GRAYSCALE)

# 转换为灰度图像
# gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# 添加高斯噪声
mean = 0
variance = 0.01
gaussian_noise = np.random.normal(mean, variance ** 0.7, image.shape)
noisy_image = cv2.add(image.astype(np.float64), gaussian_noise)

# 定义变换矩阵
M = np.array([[1, 0, 0],
              [0, 1, 0]], dtype=np.float32)
# 进行维纳滤波
filtered_image = cv2.warpAffine(noisy_image, M, image.shape[::-1])
filtered_image = cv2.normalize(filtered_image, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8)

# 显示结果
cv2.imshow('Noisy Image', noisy_image.astype(np.uint8))
cv2.imshow('Filtered Image', filtered_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
